import java.sql.{Connection, DriverManager}

object test04 {
  var conn: Connection = null
  def main(args: Array[String]): Unit = {

    try {
      Class.forName("com.mysql.jdbc.Driver")
      println("驱动加载成功")
      conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/test?user=root&password=123456&useSSL=false")
      println("数据库连接成功")
      val statement = conn.createStatement()
      val resultSet = statement.executeQuery("select * from mystu")
      while(resultSet.next()){
        println(resultSet.getString(2))
      }
    } catch {
      case _:Exception => 0
    } finally {
      conn.close()
      println(1111111)
    }

  }
}
